﻿// -----------------------------------------------------------------------
// <copyright file="StatusQueryMessageControl.cs" company="Zen Design Corp">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Zen.BlackBerry.Pap.Control
{
	using System.Collections.Generic;
	using System.Linq;
	using System.Xml;
	using System.Xml.Serialization;
	using System.Xml.Schema;
	using System;

	/// <summary>
	/// Represents the Status Query PAP request message control (XML).
	/// </summary>
	public class StatusQueryMessageControl : PapControl, IXmlSerializable
	{
		private AddressList _addresses;

		/// <summary>
		/// Initializes a new instance of the <see cref="StatusQueryMessageControl"/> class.
		/// </summary>
		public StatusQueryMessageControl()
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="StatusQueryMessageControl"/> class.
		/// </summary>
		/// <param name="isUsingPublicPush">if set to <c>true</c> [is using public push].</param>
		public StatusQueryMessageControl(bool isUsingPublicPush)
		{
			IsUsingPublicPush = isUsingPublicPush;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="StatusQueryMessageControl"/> class.
		/// </summary>
		/// <param name="isUsingPublicPush">if set to <c>true</c> [is using public push].</param>
		/// <param name="pushId">The push id.</param>
		public StatusQueryMessageControl(bool isUsingPublicPush, string pushId)
		{
			IsUsingPublicPush = isUsingPublicPush;
			PushId = pushId;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="StatusQueryMessageControl"/> class.
		/// </summary>
		/// <param name="isUsingPublicPush">if set to <c>true</c> [is using public push].</param>
		/// <param name="pushId">The push id.</param>
		/// <param name="addresses">The addresses.</param>
		public StatusQueryMessageControl(bool isUsingPublicPush, string pushId, params string[] addresses)
		{
			IsUsingPublicPush = isUsingPublicPush;
			PushId = pushId;
			Addresses.AddRange(addresses);
		}

		/// <summary>
		/// Gets or sets the push id.
		/// </summary>
		/// <value>The push id.</value>
		public string PushId
		{
			get;
			set;
		}

		/// <summary>
		/// Gets the addresses.
		/// </summary>
		/// <value>The addresses.</value>
		public AddressList Addresses
		{
			get
			{
				if (_addresses == null)
				{
					_addresses = new AddressList();
					_addresses.IsUsingPublicPush = IsUsingPublicPush;
				}
				return _addresses;
			}
		}

		#region IXmlSerializable Members

		/// <summary>
		/// This method is reserved and should not be used. When implementing the IXmlSerializable interface, you should return null (Nothing in Visual Basic) from this method, and instead, if specifying a custom schema is required, apply the <see cref="T:System.Xml.Serialization.XmlSchemaProviderAttribute"/> to the class.
		/// </summary>
		/// <returns>
		/// An <see cref="T:System.Xml.Schema.XmlSchema"/> that describes the XML representation of the object that is produced by the <see cref="M:System.Xml.Serialization.IXmlSerializable.WriteXml(System.Xml.XmlWriter)"/> method and consumed by the <see cref="M:System.Xml.Serialization.IXmlSerializable.ReadXml(System.Xml.XmlReader)"/> method.
		/// </returns>
		public XmlSchema GetSchema()
		{
			return null;
		}

		/// <summary>
		/// Generates an object from its XML representation.
		/// </summary>
		/// <param name="reader">The <see cref="T:System.Xml.XmlReader"/> stream from which the object is deserialized.</param>
		public void ReadXml(XmlReader reader)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Converts an object into its XML representation.
		/// </summary>
		/// <param name="writer">The <see cref="T:System.Xml.XmlWriter"/> stream to which the object is serialized.</param>
		public void WriteXml(XmlWriter writer)
		{
			writer.WriteAttributeString("push-id", PushId);
			Addresses.WriteXml(writer);
		}

		#endregion
	}
}
